package com.struggle.myrabbitmq.sample.work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.struggle.myrabbitmq.sample.MyRabbitConstants;
import com.struggle.myrabbitmq.util.ConnectionUtil;
import lombok.SneakyThrows;

import java.io.IOException;

/**
 * @className Send
 * @Description work模式：rabbitMQ生成者发送消息
 * @Author liuwj3
 * @Date 2019/9/19 0019 下午 3:59
 **/
public class Send {
    @SneakyThrows
    public static void main(String[] args)  {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare(MyRabbitConstants.QUEUE_NAME_WORK, false, false, false, null);
        for (int i = 0; i < 10; i++) {
            String message = "第" + i + "次hello world";
            channel.basicPublish("", MyRabbitConstants.QUEUE_NAME_WORK, null, message.getBytes());
            System.out.println(" [X] Sent '" + message + "'");
            Thread.sleep(i * 10);
        }

        channel.close();
        connection.close();;

    }
}
